<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <base href="${request.contextPath}/"/>
    <meta charset="UTF-8">
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,minimum-scale=1.0">
    <title>漠河智慧社区</title>
    <link href="Content/wechat/css/reset.css" rel="stylesheet" type="text/css">
    <!--签到-->
    <link href="Content/wechat/css/dangJian_gongZhuGongJian_CJHD.css" rel="stylesheet" type="text/css">

    <script src="Content/wechat/js/jquery.min.js"></script>
    <!--字体缩放-->
    <script src="Content/wechat/js/ziti.js"></script>
    <script src="Content/wechat/js/jquery.validate.js"></script>


</head>
<body>
<header class="clearfix">
    <h2>报名参加</h2><button class="quxiao_btn">取消</button>
</header>
<div class="xinyuan">
    <form id="form">
        <div class="xinyuan_box">
            <input  type="hidden" name="ceactivityid" id="ceactivityid" value="${ceactivityid}" />
            <dl class="clearfix">
                <dt>姓名</dt>
                <dd>
                    <input class="text" type="text" name="campaignname" id="campaignname" placeholder="请输入姓名">
                    <label hidden="hidden" id="realizename-errorsj1" class="error"></label>
                </dd>
            </dl>
            <dl class="clearfix">
                <dt>联系电话</dt>
                <dd>
                    <input class="text" type="text" name="campaignphone" id="campaignphone" placeholder="请输入联系电话">
                    <label hidden="hidden" id="realizename-errorsj" class="error"></label>
                </dd>
            </dl>
            <dl class="clearfix">
                <dt>所属小区</dt>
                <dd>
                <select  name="villageid" id="villageid">
                    <#list villList as item>
                        <option value="${item.id}">${item.villagename !}</option>
                    </#list>
                </select>
                </dd>
            </dl>
            <h4>参加理由：</h4>
            <textarea class="textarea" name="content" id="content"  placeholder="请简要说明"></textarea>
        </div>
    </form>
    <div class="button_shangChuan" id="btnAdd">报名</div>
</div>
</body>
<script type="text/javascript">
    var btnAdd = true;
    $().ready(function () {
        $(".button_shangChuan").click(function () {
            if (!btnAdd) {
                alert("保存中...");
                return;
            }
            var campaignphone = document.getElementById('campaignphone').value;
            if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(campaignphone))){
                $("#realizename-errorsj").html("请输入正确的手机号格式");
                return false;
            }
            var campaignname = $("#campaignname").val();
            var villageid = $("#villageid").val();
            $.ajax({
                url: "wechat/home/party/report/ajax_huodong_baoming",
                type: 'POST',
                async: false,
                dataType:"json",
                data:{"campaignname":campaignname,"campaignphone":campaignphone,"villageid":villageid},
                success:function (msg) {
                    if (msg == "1"){
                        $("#realizename-errorsj1").html("已经报名了");
                        flag = false;
                        return false;
                    }else{
                        flag = true;
                        return true;
                    }
                },
            })
            if(flag == false){
                return false;
            }

            if ($("#form").valid()) {
                if (true) {
                    btnAdd = false;
                    $("#btnAdd").html("保存中...")
                    $.ajax({
                        //几个参数需要注意一下
                        type: "POST",//方法类型
                        dataType: "json",//预期服务器返回的数据类型
                        url: "/wechat/home/party/report/report_join_saveForm",//url
                        data: $('#form').serialize(),
                        success: function (result) {
                            console.log(result);//打印服务端返回的数据(调试用)
                            if (result.code == 200) {
                                window.location.href = "wechat/home/party/report/report_index"
//                                    alert(result.info);
//                                    location.reload();
                            } else {
                                alert("请稍后再试");
                                btnAdd = true;
                                $("#btnAdd").html("保存中");
                            }
                        },
                        error: function () {
                            alert("异常！");
                            btnAdd = true;
                            $("#btnAdd").html("保存");
                        }
                    });
                }
            }
        });
        $("#form").validate({
            rules: {
                campaignname: {
                    required: true,
                    minlength: 2,
                    maxlength: 13,

                },
                content: {
                    required: true,
                    minlength: 5,
                    maxlength: 500,

                }
//                ,
//                overday: {
//                    required: true,
//                    Validateoverday: true
//
//                }
            },
            messages: {
                campaignname: {
                    minlength: "(字符不能少于 2 个且不能大于 13个)",
                    maxlength: "(字符不能少于 2 个且不能大于 13个)",
                },
                content: {
                    minlength: "(字符不能少于 5 个且不能大于 500个)",
                    maxlength: "(字符不能少于 5 个且不能大于 500个)",
                }
            }


        })
//        jQuery.validator.addMethod("Validateoverday", function (value, element) {
//            return this.optional(element) || (/^[1-9]\d*$/.test(value));
//        }, "请输入正整数");
    });

</script>
</html>
